package com.xujc.controller;

import com.opensymphony.xwork2.ActionSupport;
import com.xujc.dao.IUserDAO;
import org.apache.struts2.interceptor.CookiesAware;

import java.util.Map;

/**
 * Created by xujc on 6/17/15.
 */
public class LoginAction extends ActionSupport implements CookiesAware {
    private IUserDAO mIUserDAO;
    private Map<String, String> mCookies;
    private String mUsername;
    private String mPassword;
    private String mReferUrl;

    public String getReferUrl() {
        return mReferUrl;
    }

    public void setReferUrl(String referUrl) {
        mReferUrl = referUrl;
    }

    public String getUsername() {
        return mUsername;
    }

    public void setUsername(String username) {
        mUsername = username;
    }

    public String getPassword() {
        return mPassword;
    }

    public void setPassword(String password) {
        mPassword = password;
    }

    public void setUserDAO(IUserDAO userDAO) {
        mIUserDAO=userDAO;
    }

    @Override
    public void setCookiesMap(Map<String, String> map) {
        mCookies = map;
    }

    @Override
    public String execute() throws Exception {
        if (mCookies==null){
            return SUCCESS;
        }
        if (mCookies.get("uid")!=null){
            String uid = mCookies.get("uid");
            return LOGIN;
        } else {
            return SUCCESS;
        }
    }
}
